package com.wtb.javatool.service.impl;

import com.wtb.javatool.dao.MajorMapper;
import com.wtb.javatool.dao.MajorScoreMapper;
import com.wtb.javatool.entity.Major;
import com.wtb.javatool.entity.MajorScore;
import com.wtb.javatool.service.IMajorScoreService;
import com.wtb.javatool.vo.MajorScoreDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MajorScoreService implements IMajorScoreService {

    @Autowired
    private MajorScoreMapper majorScoreMapper;

    @Autowired
    private MajorMapper majorMapper;

    @Override
    public void save(MajorScore majorScore) {
        majorScore.setSubmit_time(new Date());
        majorScore.setReview_status(0);
//        MajorScore data = majorScoreMapper.selectByMajorCode(majorScore.getMajorCode());
//        if (data != null){
//            Major major = new Major();
//            major.setMajorCode(majorScore.getMajorCode());
//            major.setDisabled(1);
//            majorMapper.updateMajorDisabled(major);
//            throw new RuntimeException("该专业已经提交过评估，不能重复提交");
//        }
        majorScoreMapper.save(majorScore);
    }

    @Override
    public void temp(MajorScore majorScore) {
        majorScore.setReview_status(0);
        majorScore.setSubmit_status(1);
        majorScoreMapper.save(majorScore);
    }

    @Override
    public MajorScoreDto selectByMajorCode(String majorCode) {
        MajorScoreDto majorScoreDto = majorScoreMapper.selectByMajorCode(majorCode);
        return majorScoreDto;
    }

    @Override
    public void approve(MajorScore majorScore) {
        majorScore.setReview_status(1);
        majorScore.setReview_time(new Date());
        majorScoreMapper.updateReview(majorScore);
    }

    @Override
    public void disApprove(MajorScore majorScore) {
        majorScore.setReview_status(2);
        majorScore.setReview_time(new Date());
        majorScoreMapper.updateReview(majorScore);
    }

}
